home *** CD-ROM | disk | FTP | other *** search
- // Personnell DataBase
- // (C) Copyright 1992 Campbell Soup Company by Andrew Frantz
- // CSDUDES.CPP
- // contains the source for the TApplication class and the main driver
- // CIS --- 70712,3547
- // =====================================================================
- #include "csdudes.hpp"
- // =====================================================================
- // The first PX data class must also init the engine
- // initialization of static member vars
- PXPerson* TPersonnellApp::PersonDB = new PXPerson();
- PXCostCtr* TPersonnellApp::CostCtrDB = new PXCostCtr();
- // =====================================================================
- void testCore()
- {
- char mess[80];
- sprintf(mess, "Coreleft = %lu", (unsigned long) coreleft());
- messageBox(mess, mfError);
- }
- // ============ TV Application class ===================================
- TPersonnellApp::TPersonnellApp() :
- TProgInit( &TPersonnellApp::initStatusLine,
- &TPersonnellApp::initMenuBar,
- &TPersonnellApp::initDeskTop)
- {
- }
- // =====================================================================
- void TPersonnellApp::handleEvent(TEvent& event)
- {
- TApplication::handleEvent(event);
- TDialog *dialog;
-
- if( event.what == evCommand )
- {
- switch( event.message.command )
- {
- case cmPersonAddDialog:
- // testCore();
- dialog = (TPersonDlg *) validView( new TPersonDlg("Add Person", TPersonDlg::AddDlg));
- if(dialog != 0)
- deskTop->execView(dialog);
- destroy(dialog);
- // testCore();
- break;
- case cmPersonEditDialog:
- // testCore();
- dialog = (TPersonDlg *) validView( new TPersonDlg("Edit Person", TPersonDlg::EditDlg));
- if(dialog != 0)
- deskTop->execView(dialog);
- destroy(dialog);
- // testCore();
- break;
- case cmCostCtrAddDialog:
- dialog = (TCostCtrDlg *) validView( new TCostCtrDlg("Add Cost Center", TCostCtrDlg::AddDlg));
- if(dialog != 0)
- deskTop->execView(dialog);
- destroy(dialog);
- break;
- case cmCostCtrEditDialog:
- dialog = (TCostCtrDlg *) validView( new TCostCtrDlg("Edit Cost Center", TCostCtrDlg::EditDlg));
- if(dialog != 0)
- deskTop->execView(dialog);
- destroy(dialog);
- break;
- case cmAboutCmd: // About Dialog Box
- aboutDlgBox();
- break;
- default:
- return;
- }
- clearEvent( event ); // clear event after handling
- }
- }
- // =====================================================================
- TMenuBar *TPersonnellApp::initMenuBar( TRect r )
- {
- TSubMenu& sub1 =
- *new TSubMenu( "~\360~", 0 ) +
- *new TMenuItem( "~A~bout...", cmAboutCmd, kbNoKey, hcNoContext);
-
- TSubMenu& sub2 =
- *new TSubMenu( "~D~ata Entry", kbAltD )+
- *new TMenuItem( "~P~eople", cmPersonAddDialog, kbF3, hcNoContext, "F3" )+
- *new TMenuItem( "~C~ost Ctr", cmCostCtrAddDialog, kbF4, hcNoContext, "F4" )+
- newLine()+
- *new TMenuItem( "E~x~it", cmQuit, cmQuit, hcNoContext, "Alt-X" );
-
- TSubMenu& sub3 =
- *new TSubMenu( "Data ~E~dit", kbAltE )+
- *new TMenuItem( "~P~eople", cmPersonEditDialog, kbF5, hcNoContext, "F5" )+
- *new TMenuItem( "~C~ost Ctr", cmCostCtrEditDialog, kbF6, hcNoContext, "F6" );
-
- r.b.y = r.a.y + 1;
- return (new TMenuBar( r, sub1 + sub2 + sub3 ) );
- }
- // =====================================================================
- TStatusLine *TPersonnellApp::initStatusLine( TRect r )
- {
- r.a.y = r.b.y - 1; // move top to 1 line above bottom
- return (new TStatusLine( r,
- *new TStatusDef( 0, 0xFFFF ) +
- *new TStatusItem( "~Alt-X~ Exit", kbAltX, cmQuit ) +
- *new TStatusItem( 0, kbF10, cmMenu ) ));
- }
- // =====================================================================
- void TPersonnellApp::aboutDlgBox()
- {
- TDialog *aboutBox = new TDialog(TRect(0, 0, 39, 13), "About");
-
- aboutBox->insert(
- new TStaticText(TRect(9, 2, 30, 9),
- "\003Personnell DataBase\n\003\n" // These strings will be
- "\003Beta Version\n\003\n" // concatenated by the compiler.
- "\003Copyright (c) 1992\n\003\n" // The Ctrl-C centers the line.
- "\003Campbell Soup"
- )
- );
-
- aboutBox->insert(new TButton(TRect(14, 10, 25, 12), " OK", cmOK, bfDefault));
-
- aboutBox->options |= ofCentered;
-
- deskTop->execView(aboutBox);
-
- destroy( aboutBox );
- }
- // =====================================================================
- // AFF add functionality for Enter key on field and Select Button
- // Stuff a message into event queue if double click or Button hit
- void TMyListBox::handleEvent(TEvent& event)
- {
- int doIt=0;
- if((event.what == evMouseDown) && (event.mouse.doubleClick))
- {
- doIt = 1;
- }
- else if((event.what == evKeyDown) && (event.keyDown.keyCode == kbEnter))
- {
- doIt = 1;
- }
- else
- doIt=0;
-
- if(doIt)
- {
- message(owner,evBroadcast,cmListItemSelected,this);
- clearEvent(event);
- }
- TListBox::handleEvent(event);
- }
- // =====================================================================
- TCCListDlg::TCCListDlg(TRect& bounds,char *aTitle) :
- TDialog(bounds,aTitle),
- TWindowInit(&TCCListDlg::initFrame)
- {
- TStringCollection *theCollection = new TStringCollection(100,10);
-
- TPersonnellApp::CostCtrDB->recfirst();
- do {
- TPersonnellApp::CostCtrDB->recget();
- TPersonnellApp::CostCtrDB->CostCtr.get();
- theCollection->insert(newStr(TPersonnellApp::CostCtrDB->CostCtr));
- } while(TPersonnellApp::CostCtrDB->recnext() == PXSUCCESS);
-
- options |= ofCentered;
- eventMask |= evBroadcast;
-
- TScrollBar *listScroller = new TScrollBar(TRect(47,2,48,10));
-
- listBox = new TMyListBox(TRect(3,2,47,10),2,listScroller);
-
- listBox->newList(theCollection);
-
- insert(listBox);
- insert(listScroller);
-
- // insert(new TButton(TRect(22,19,32,21),"~S~elect",cmListItemSelected,bfDefault));
-
- selectNext(False);
- }
- // =====================================================================
- void TCCListDlg::handleEvent(TEvent& event)
- {
- char msg[20];
- if ((event.what == evBroadcast) && (event.message.command == cmListItemSelected))
- {
- listBox->getText(msg,listBox->focused,5);
- message(owner,evBroadcast,cmInterView,msg); //Inter-view communication
- clearEvent(event);
- message(owner,evCommand,cmClose,this); // close the ListDlg
- clearEvent(event);
- }
- TDialog::handleEvent(event);
- }
- // =====================================================================
- // Addeds this from C++ Report February 1992
- // called when new object fails.. set with set_new_handler(new_failure)
- void new_failure()
- {
- messageBox("Memory Allocation error ...Exiting !", mfError);
- cout << "Memory Allocation error ...Exiting !\n";
- PXExit();
- exit(-1);
- }
- // =====================================================================
- int main(int argc, char **argv)
- {
- set_new_handler(new_failure);
- TPersonnellApp TestApp;
- // testCore();
- TestApp.run();
- PXExit();
- return 0;
- }
- // =====================================================================
-